<%@ page session="false" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://myfaces.apache.org/trinidad" prefix="tr"%>
<%@taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh"%>

<tr:panelGroupLayout>
<fieldset><legend>Prowizje dodatkowe</legend>
<table width="100%" cellspacing="0" cellpadding="3" border="0" 
		style="margin-top:10px; border: 1px solid #ccc">
	<tr>
	<td>
		<tr:commandLink shortDesc="Dodaj prowizję"
						rendered="#{empty feeInvitationBean}"
						actionListener="#{invitationController.addEmptyFee}"
						id="addFeeButton" >
				<tr:image source="gfx/add32.png" />
		</tr:commandLink>
		<tr:commandLink shortDesc="Zapisz prowizję"
						rendered="#{not empty feeInvitationBean}"
						actionListener="#{invitationController.saveFeeToInvitation}"
						id="saveFeeButton">
				<tr:image source="gfx/save_button.png" />
		</tr:commandLink>
		</td>
	
		<td colspan="3">
			<tr:selectOneChoice value="#{feeInvitationBean.priceParameter}"
								required="true" id="priceParameter" label="Typ prowizji:"
								rendered="#{not empty feeInvitationBean}">
				<tr:forEach items="#{invitationController.priceParameterList}" var="priceType">
					<f:selectItem itemValue="#{priceType}" itemLabel="#{priceType.name} - #{priceType.price} PLN"/>
				</tr:forEach>
			</tr:selectOneChoice>
		</td>
		<td>
			<tr:inputText value="#{feeInvitationBean.multiply}" label="krotność:"
							required="true" rendered="#{not empty feeInvitationBean}"
							partialTriggers="saveFeeButton"
							onkeypress="return checkField(window.event, DIGIT_FIELD)"/>
		</td>
	</tr>
	<tr:iterator value="#{invitationBean.feeInvitations}"
					binding="#{invitationController.feeIterator}" 
					id="feeList" var="fee">
		<tr onMouseOver="this.style.backgroundColor='#e0ffc2'" onMouseOut="this.style.backgroundColor='#FFF'">
			<td style="border-top: 1px solid #ccc">
				<tr:outputText value="#{fee.priceParameter.name }"/>
			</td>
			<td style="border-top: 1px solid #ccc" width="30">
				<tr:outputText value="#{fee.priceParameter.price}">
					<f:convertNumber groupingUsed="false" maxFractionDigits="2" minFractionDigits="2" locale="pl" />
				</tr:outputText>
			</td>
			<td style="border-top: 1px solid #ccc" width="40">
				<tr:outputText value="x #{fee.multiply}  = "/>
			</td>
			<td style="border-top: 1px solid #ccc" width="50">
				<tr:outputText value="#{fee.multiply * fee.priceParameter.price} PLN">
					<f:convertNumber groupingUsed="false" maxFractionDigits="2" minFractionDigits="2" locale="pl" />
				</tr:outputText>
			</td>
			<td style="border-top: 1px solid #ccc" align="right" width="20">
			<tr:commandLink shortDesc="Usuń prowizję" id="removeFeeButton"
                				actionListener="#{invitationController.removeFee}"
                            	onclick="return confirmMessageBox('Czy chcesz usunąć tę prowizję?');">
                <tr:image source="gfx/delete.png" />
            </tr:commandLink>
			</td>			
						
		</tr>
	</tr:iterator>
</table>
</fieldset>
</tr:panelGroupLayout>